﻿using System;
using System.Globalization;
using System.Text;

internal class SupportClass
{
    internal static byte[] ToByteArray(object[] tempObjectArray)
    {
        byte[] buffer = null;
        if (tempObjectArray != null)
        {
            buffer = new byte[tempObjectArray.Length];
            for (int i = 0; i < tempObjectArray.Length; i++)
            {
                buffer[i] = (byte) tempObjectArray[i];
            }
        }
        return buffer;
    }

    internal static byte[] ToByteArray(string sourceString)
    {
        return Encoding.UTF8.GetBytes(sourceString);
    }

    internal static byte[] ToByteArray(sbyte[] sbyteArray)
    {
        byte[] buffer = null;
        if (sbyteArray != null)
        {
            buffer = new byte[sbyteArray.Length];
            for (int i = 0; i < sbyteArray.Length; i++)
            {
                buffer[i] = (byte) sbyteArray[i];
            }
        }
        return buffer;
    }

    internal static char[] ToCharArray(byte[] byteArray)
    {
        return Encoding.UTF8.GetChars(byteArray);
    }

    internal static char[] ToCharArray(sbyte[] sByteArray)
    {
        return Encoding.UTF8.GetChars(ToByteArray(sByteArray));
    }

    internal class ArraySupport
    {
        internal static bool Equals(Array array1, Array array2)
        {
            bool flag = false;
            if ((array1 == null) && (array2 == null))
            {
                return true;
            }
            if (((array1 != null) && (array2 != null)) && (array1.Length == array2.Length))
            {
                int length = array1.Length;
                flag = true;
                for (int i = 0; i < length; i++)
                {
                    if (!array1.GetValue(i).Equals(array2.GetValue(i)))
                    {
                        return false;
                    }
                }
            }
            return flag;
        }

        internal static void Fill(Array array, object val)
        {
            Fill(array, 0, array.Length, val);
        }

        internal static void Fill(Array array, int fromindex, int toindex, object val)
        {
            object obj2 = val;
            Type elementType = array.GetType().GetElementType();
            if (elementType != val.GetType())
            {
                obj2 = Convert.ChangeType(val, elementType, CultureInfo.InvariantCulture);
            }
            if (array.Length == 0)
            {
                throw new NullReferenceException();
            }
            if (fromindex > toindex)
            {
                throw new ArgumentException();
            }
            if ((fromindex < 0) || (array.Length < toindex))
            {
                throw new IndexOutOfRangeException();
            }
            for (int i = (fromindex > 0) ? fromindex-- : fromindex; i < toindex; i++)
            {
                array.SetValue(obj2, i);
            }
        }
    }
}

